"use strict";

const commonService = requireService("common");
const url = require("url");

/**
 * api 默认版本
 * @type {String}
 */
var apiConf = getSysConfig("apiConf") || {};
const DEF_VERSIONS = {
    "/sdk/collect": apiConf.version || "1.1.0"
}

/**
 * 获取物料外部通用接口
 */
function onGet(ctx) {
    var version = ctx.query.v || DEF_VERSIONS[`/sdk/${ctx.params.type}`];
    if (!version) {
        ctx.body = "";
        return;
    }
    commonService.setHeader.call(ctx);
    ctx.body = commonService.buildSDKScriptLoader(
        url.format({
            "host": ctx.header.host
            ,"protocol": "http"
            ,"pathname": `/api/sdk/${version}/collect/${ctx.params.customer}/${ctx.params.ent_id}`
            ,"query": ctx.query
        })
    );
}

module.exports = {
    "/sdk/at/:type/:customer/:ent_id":["GET", onGet]
}
